package net.maku.module.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.module.organization.convert.RoleConvert;
import net.maku.module.organization.entity.RoleEntity;
import net.maku.module.organization.service.RoleService;
import net.maku.module.organization.vo.RoleVO;
import net.maku.newbase.NewBaseController;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务_角色
 *
 * @author
 */
@RestController
@RequestMapping("nb/role")
@Tag(name = "业务_角色")
@AllArgsConstructor
public class RoleController extends NewBaseController<RoleService, RoleEntity> {

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<RoleVO>> page(PageParam page, NewQuery query) {
        LambdaQueryWrapper<RoleEntity> select = new LambdaQueryWrapper<>();

        IPage<RoleEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<>(RoleConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));
    }

    @GetMapping("list")
    @Operation(summary = "全部")
    public Result<List<RoleVO>> list(NewQuery query) {
        return Result.ok(RoleConvert.INSTANCE.convertList(entityService.list()));
    }

}